package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.EmployeeBean;
import com.project.bean.InboxBean;
import com.project.bean.MailBean;
import com.project.service.IInboxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("receiveMail")
public class InboxController {
    @Autowired
    private IInboxService service;

    @RequestMapping("cutByItem")
    public IPage<InboxBean> cutByItem(Integer pageNO, String subject,
                                      LocalDate startDate, LocalDate endDate, HttpServletRequest req) {
        EmployeeBean em = (EmployeeBean) req.getSession().getAttribute("loginEm");
        IPage<InboxBean> ip = service.cutByItem(pageNO, em.getEmId(), subject, startDate, endDate);
        return ip;
    }

    @RequestMapping("findById")
    public MailBean findById(Integer inboxId, Integer mailId) {
        return service.findById(inboxId, mailId);
    }

    @RequestMapping("del")
    public String del(Integer id) {
        service.del(id);
        return "delOK";
    }
}
